<!-- eslint-disable max-len -->
<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>黑马面经后台管理系统</span>
      </div>
      <el-form label-position="top" :model="user" :rules="rules" ref="form" label-width="100px">
        <el-form-item label="用户名:" prop="username">
          <el-input type="text" v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item label="密码:" prop="password">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
        ],
        passwoed: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
        ],
      },
    };
  },

  methods: {
    submitForm() {
      // eslint-disable-next-line consistent-return
      this.$refs.form.validate();
      console.log('校验通过');
      this.$store.dispatch('user/getToken', this.user);
      // 成功消息提示
      this.open();
      // 跳转到首页
      this.$router.push('/');
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
    open() {
      this.$notify({
        title: '哈喽,打工人!又是美好的一天!',
        // message: '登录成功',
        type: 'success',
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-card {
  width: 420px;
  margin: 10% auto;

  // 深度作用选择器   ::v-deep   /deep/
  ::v-deep .el-card__header {
    background: rgba(114, 124, 245, 1);
    text-align: center;
    color: white;
  }

  ::v-deep .el-form-item__content {
    display: flex;
    justify-content: center;
  }
}
</style>
